#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"QBoxLayout"
#include"QTimer"
#include"data.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //连接
    connectForm=new ConnectForm(this);
    QHBoxLayout *hlayout=new QHBoxLayout(ui->tab);
    hlayout->addWidget(connectForm);

    //位置比较
    hwRegForm=new HwPs_Regist_Form(ui->tab_11);
    hlayout=new QHBoxLayout(ui->tab_11);
    hlayout->addWidget(hwRegForm);

    //自动电子凸轮
    autoCamForm=new AutoCamForm(ui->tab_10);
    hlayout=new QHBoxLayout(ui->tab_10);
    hlayout->addWidget(autoCamForm);

    //IO
    ioForm=new io(ui->tab_6);
    hlayout=new QHBoxLayout(ui->tab_6);
    hlayout->addWidget(ioForm);

    //直线插补
    moveLineForm=new MoveLineForm(ui->tab_2);
    hlayout=new QHBoxLayout(ui->tab_2);
    hlayout->addWidget(moveLineForm);

    //圆弧插补
    moveCircleForm=new MoveCircleForm(ui->tab_3);
    hlayout=new QHBoxLayout(ui->tab_3);
    hlayout->addWidget(moveCircleForm);

    //回原
    goHomeForm=new GoHomeForm(ui->tab_14);
    hlayout=new QHBoxLayout(ui->tab_14);
    hlayout->addWidget(goHomeForm);

    //螺旋插补
    mHelicalForm=new MHelicalForm(ui->tab_5);
    hlayout=new QHBoxLayout(ui->tab_5);
    hlayout->addWidget(mHelicalForm);

    //连续插补
    mContinuityForm=new MContinuityForm(ui->tab_4);
    hlayout=new QHBoxLayout(ui->tab_4);
    hlayout->addWidget(mContinuityForm);

    //封装函数
    packDiyForm=new PackDiyForm(ui->tab_13);
    hlayout=new QHBoxLayout(ui->tab_13);
    hlayout->addWidget(packDiyForm);

    //报警
    warnAxisForm=new WarnAxisForm(ui->tab_7);
    hlayout=new QHBoxLayout(ui->tab_7);
    hlayout->addWidget(warnAxisForm);

    //手轮
    handWheelForm=new HandWheelForm(ui->tab_8);
    hlayout=new QHBoxLayout(ui->tab_8);
    hlayout->addWidget(handWheelForm);

    //凸轮跟随
    camWheelForm=new CamWheelForm(ui->tab_9);
    hlayout=new QHBoxLayout(ui->tab_9);
    hlayout->addWidget(camWheelForm);

    //上位机与Basic交互
    pcBasicInt=new PCBasicIntForm(ui->tab_12);
    hlayout=new QHBoxLayout(ui->tab_12);
    hlayout->addWidget(pcBasicInt);

    timer=new QTimer(this);
    timer->setInterval(300);
    timer->start();
    connect(timer,&QTimer::timeout,this,&MainWindow::timerOut);

    ui->tabWidget->setCurrentIndex(0);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::timerOut(){
    if(Data::CardIsConnect()){
        this->setWindowTitle(tr("控制卡已连接"));
    }else{
        this->setWindowTitle(tr("控制卡未连接"));
    }

}

void MainWindow::on_tabWidget_currentChanged(int index)
{
    if(!Data::CardIsConnect()){
        ui->tabWidget->setCurrentIndex(0);
    }
}

